package com.potenza.training.reply.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.reply.dao.KeyWordDao;
import com.potenza.training.reply.entity.KeyWordEntity;
import com.potenza.training.reply.service.KeyWordService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("keyWordService")
public class KeyWordServiceImpl extends ServiceImpl<KeyWordDao, KeyWordEntity> implements KeyWordService {

    @Autowired(required = false)
    private KeyWordDao keyWordDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<KeyWordEntity> page = this.page(
                new Query<KeyWordEntity>().getPage(params),
                new QueryWrapper<KeyWordEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<KeyWordEntity> findbysubjectid(Long id) {
        QueryWrapper<KeyWordEntity> keyWordEntityQueryWrapper = new QueryWrapper<>();
        keyWordEntityQueryWrapper.lambda().eq(KeyWordEntity::getTbSubjectId,id);

        return keyWordDao.selectList(keyWordEntityQueryWrapper);
    }

    @Override
    public List<KeyWordEntity> findbyid(Long subjectId) {
        QueryWrapper<KeyWordEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KeyWordEntity::getTbSubjectId,subjectId);
        return list(queryWrapper);
    }

    @Override
    public void deletekeyWord(Long id) {
        QueryWrapper<KeyWordEntity> keyWordEntityQueryWrapper = new QueryWrapper<>();
        keyWordEntityQueryWrapper.lambda().eq(KeyWordEntity::getTbSubjectId,id);
        keyWordDao.delete(keyWordEntityQueryWrapper);

    }


}